package org.idea.spring.datasource;

import org.idea.spring.datasource.bean.User;
import org.idea.spring.datasource.dbcp.service.DataSourceService;
import org.idea.spring.datasource.ibernate.dao.UserDao;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import javax.annotation.Resource;
import java.util.List;


/**
 * @Author linhao
 * @Date created in 12:18 下午 2021/5/17
 */
@SpringBootApplication
public class Application implements CommandLineRunner {

    @Resource
    private DataSourceService dataSourceService;
    @Resource
    private ApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }

    @Override
    public void run(String... args) throws Exception {
//        dataSourceService.doTest();
//        userDao.findAll();
        UserDao userDao = (UserDao) applicationContext.getBean("userDao");
        List<User> users = userDao.findAll();
        System.out.println(userDao.findOne());
        System.out.println(users);
    }
}
